/**
 * ## 去除为空及不需要的参数
 * @description 描述信息
 * @remarks 备注
 * @param {string} object  [参数对象]
 * @param {string[]} strs  [字段名称集合]
 * @returns {void}
 */
export function removeUnnecessaryParams(object: Record<string, any>, strs: string[] = []): void {
  // console.log(strs);

  const nullStr = []
  if (Verify.isArray(object)) {
    (object as Record<string, any>[]).forEach(item =>
      removeUnnecessaryParams(item, strs),
    )
    return
  }
  for (const key in object) {
    if (!object[key] && typeof object[key] !== 'number') {
      nullStr.push(key)
    }
  }

  const defaultStr = [
    'creationTime',
    'creationId',
    'updateTime',
    'updateId',
    'deleteFlag',
    'deleted',
    'creationUserName',
    'updateUserName',
  ];
  // console.log([...defaultStr, ...nullStr, ...strs], strs);

  [...defaultStr, ...nullStr, ...strs].forEach(str =>
    Reflect.deleteProperty(object, str),
  )
}
type OmitArr<T> = T extends string[]
  ? T[number]
  : T extends Record<string, any>
    ? keyof T
    : string
/**
 * ## 生成通用表单验证规则
 * @description 描述信息
 * @remarks 备注
 * @param {string[] | object} target [数据对象]
 * @param {string[]} omit [去除属性]
 * @param {object} merge [所需合并验证]
 * @returns {object}
 * @example
 * ```typescript
 * generateCurrencyFormRules(['a', 'b', 'c'] as const, ['b'], {});
 * generateCurrencyFormRules({d: 1,e: 2,f: 3},['d'],{});
 * ```
 */
export function generateCurrencyFormRules<
  T extends Record<string, any> | string[] = [],
  O extends OmitArr<T> = any,
  M extends Exclude<OmitArr<T>, O> = any,
>(
  target: T,
  omit?: O[],
  merge?: Partial<Record<M, Array<Record<string, any>>>>,
) {
  let n = []
  const defaultRules = [
    {
      required: true,
      message: '必填项！',
      trigger: 'blur',
    },
  ]
  const o: typeof merge = {}
  if (Verify.isObject(target)) {
    n.push(...Object.keys(target))
  }
  else {
    n.push(...(target as string[]))
  }
  if (omit && omit.length > 0) {
    n = n.filter(item => !omit.includes(item as O))
  }

  n.forEach((key) => {
    if (merge && Reflect.has(merge, key)) {
      o[key as M] = [
        ...defaultRules,
        ...(merge[key as M] as unknown as any[]),
      ]
    }
    else {
      o[key as M] = defaultRules
    }
  })
  return o
}
